#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2018/2/6 0006 10:00
# @Author  : Arliki
# @email   : hkdnxycz@outlook.com
# @File    : sina

import scrapy


class SinaSpider(scrapy.Spider):
    name = 'sina'
    start_urls = [
        'https://m.weibo.cn/api/container/getIndex?containerid=102803&client=h5&featurecode=H5tuiguang0623&need_head_cards=1&wm=90112_90001'
    ]
    allowed_domains = [
        'weibo.cn'
    ]

    def start_requests(self):
        cooke = {
            '_T_WM': '7116b8ec1f88cfe28fd024f2ef582306',
            'SCF': 'AkDoxZuSn2NBZgwI45SRnCjcEVSMD4hjTG3En68ZaQ3aXPm9EHLp3UX5z3IpDnDsO - mhE_MUzlZhX42_nu7CfEA.',
            'SUB': '_2A253fXsuDeRhGeNM41sX8CzPwz - IHXVUngVmrDV6PUJbkdAKLRPRkW1NSeSR3BQn79kWex0e3_zBP2A4VOroKnO5',
            'WEIBOCN_FROM': '1110006030',
            'WEIBOCN_WM': '90112_90001',
            'M_WEIBOCN_PARAMS': 'featurecode%3DH5tuiguang0623%26fid%3D102803%26uicode%3D10000011'
        }
        yield scrapy.Request(self.start_urls[0], callback=self.parse, cookies=cooke)

    def parse(self, response):
        cooke = response.request.headers.getlist('Cookie')[0].decode('utf-8')
        c1 = cooke.split(';')
        c2 = dict()
        for i in c1:
            k = i.strip('').split('=')
            c2[k[0]] = k[1]
        print(c2)
